package com.jichangxiu.socket.config;

import lombok.extern.slf4j.Slf4j;
import org.atmosphere.cpr.AtmosphereServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class SocketConfig {

    @Bean
    public ServletRegistrationBean servletRegistration() {
        log.debug("【Socket-Config】开启【ServletRegistrationBean】");
        ServletRegistrationBean registration = new ServletRegistrationBean(new AtmosphereServlet());
        registration.addInitParameter("org.atmosphere.cpr.packages", "com.jichangxiu.socket");
        registration.addInitParameter("org.atmosphere.interceptor.HeartbeatInterceptor.clientHeartbeatFrequencyInSeconds", "60");
        registration.setLoadOnStartup(0);
        registration.setAsyncSupported(true);
        registration.addUrlMappings("/common/socket/*");
        return registration;
    }

}
